package cn.netjava.softkid.chapter15;

import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class MailSender 
{
	public void send()
	{
		Properties props = new Properties();
		props.put("mail.smtp.host","smtp.126.com");
		props.put("mail.from","true");
		
		Session session = Session.getDefaultInstance(props);
		MimeMessage msg = new MimeMessage(session);
		for(int i=0;i<100;i++)
		{
		try {
			msg.setFrom(new InternetAddress("limeiyu520@126.com"));
			msg.addRecipient(Message.RecipientType.TO,new InternetAddress("370821989@qq.com" ));
			msg.setSubject("softkid's first javaMail!!!");
			msg.setText("I Love You!");
			
			Transport transport = session.getTransport("smtp");
			transport.connect("smtp.126.com","limeiyu520", "hnsfdxrjgc");
			transport.sendMessage(msg,msg.getAllRecipients());
			transport.close();
			Thread.sleep(20);
		} catch (MessagingException e) {
			e.printStackTrace();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println("Already send to destination address......");
		}
	}
	public static void main(String args[])
	{
		new MailSender().send();
	}
}